package topcoder;

import java.util.HashMap;

public class TheSquareRootDilemma {

	public int countPairs(int N, int M) {
		int c = 0;
		
		HashMap<Integer, Integer> xmap = new HashMap<Integer, Integer>();
		int maxx = (N+M)*(N+M);
		for(int x = 1; x <= maxx; x++)
			xmap.put(x*x, x);
		
		
		for(int b = 1; b <= M; b++) {
			
			int y = 1, x2 = b;
			while(true) {

				System.out.println(b + "\t\t" + y + "\t\t" + x2);
				
				if(xmap.containsKey(x2)){
					int x = xmap.get(x2);
					int a = y - 2*x + b;
					
					System.out.println("a = " + a);
					
					if(a > N)
						break;
					if(a > 0)
						c++;
				} 
				
				if(x2 > maxx)
					break;
				
				x2 += b;
				y++;
			}
		}
		
		return c;
	}
	
	public static void main(String[] args) {
		TheSquareRootDilemma r =new TheSquareRootDilemma();
		System.out.println(r.countPairs(2, 2));
	}
}
